<?php

require_once 'taoapi/Taoapi.php';

class Taobao {

    public $_Cfg = array();

    public function Nick() {
        return "vip7086";
    }

    function Auto_Get($data) {
        $Taoapi_Config = Taoapi_Config :: Init();
        $Taoapi_Config->setCharset('UTF8');
        $Taoapi_Config->setCache(0);
        $Taoapi_Config->setCloseError();
        $Taoapi        = new Taoapi;
        foreach ($data as $key => $value) {
            $Taoapi->$key = $value;
        }
        $TaobaokeData = $Taoapi->Send('get', 'xml')->getArrayData();
        return $TaobaokeData;
    }

    function Get_Save_Shop($cid, $Else = array()) {
        $page_size = 40;
        //得到当前是第几页
        for ($i = 1; $i < 100; $i++) {
            $pageCurrent = $i;
            $Set         = array(
                'method'    => 'taobao.taobaoke.shops.get',
                'fields'    => 'user_id,shop_title,click_url,commission_rate,seller_credit,shop_type,total_auction,auction_count',
                'nick'      => Taobao::Nick(),
                'cid'       => $cid,
                'page_no'   => $pageCurrent,
                'page_size' => $page_size
            );
            $Set        = array_merge($Set, $Else);
            $Data       = Taobao::Auto_Get($Set);
            $m          = M("taobaoke_shops");
            $relation   = M("taobaoke_shops_relation");
            foreach ($Data['taobaoke_shops']["taobaoke_shop"] as $key => $value) {
                $value['dateline'] = time();
                //$value['cid'] = $cid;
                $m->add($value, "", 1);
                $where             = array(
                    "cid"      => $cid,
                    "user_id"  => $value['user_id']
                );
                $re_status = $relation->where($where)->find();
                if ($re_status == null) {
                    $relation->add($where, "", 1);
                }
            }
            if ($Data['total_results'] < ($i + 1) * 40) {
                break;
            }
        }
    }

    function CatGetItem($cid) {
        $Taoapi_Config  = Taoapi_Config :: Init();
        $Taoapi_Config->setCharset('UTF8');
        $Taoapi_Config->setCache(0);
        $Taoapi_Config->setCloseError();
        $Taoapi         = new Taoapi;
        $Taoapi->method = 'taobao.taobaoke.items.get';
        $Taoapi->fields = 'num_iid,iid,title,nick,pic_url,price,click_url,commission,commission_rate,commission_num,commission_volume,seller_credit_score,item_location,shop_click_url,volume';
        $Taoapi->nick   = Taobao::GetNick();
        if ($keyword != "") {
            $Taoapi->keyword = $keyword;
        }
        if ($cid != "") {
            $Taoapi->cid            = $cid;
        }
        $Taoapi->start_credit   = '3diamond';
        $Taoapi->end_credit     = '5goldencrown';
        $Taoapi->sort           = 'commissionNum_desc';
        $Taoapi->start_totalnum = "1";
        $Taoapi->end_totalnum   = "10000000";
        $page                   = "1";
        $page_size              = "16";
        switch ($_GET['sort']) {
            case "1":
                $sort              = "credit_desc";
            //信用等级
            case "2":
                $sort              = "commissionVolume_desc";
            //总支出佣金从高到低
            default:
                $sort              = "commissionNum_desc";
            //成交量成高到低
        }
        $Taoapi->page_no   = $page;
        $Taoapi->page_size = $page_size;
        $Taoapi->sort      = $sort;
        $TaobaokeData      = $Taoapi->Send('get', 'xml')->getArrayData();
        return $TaobaokeData['taobaoke_items']['taobaoke_item'];
    }

    function GetShopList($cid) {
        $Taoapi_Config        = Taoapi_Config :: Init();
        $Taoapi_Config->setCharset('UTF-8');
        $Taoapi_Config->setCache(0);
        $Taoapi_Config->setCloseError();
        $Taoapi               = new Taoapi;
        $Taoapi->method       = 'taobao.taobaoke.shops.get';
        $Taoapi->cid          = $cid;
        $Taoapi->start_credit = '1diamond';
        $Taoapi->end_credit   = '5goldencrown';
        $Taoapi->fields       = 'user_id,click_url,shop_title,commission_rate,seller_credit,shop_type,auction_count,total_auction';
        $Taoapi->page_size    = "40";
        $Taoapi->nick         = Taobao::GetNick();
        $TaobaokeData         = $Taoapi->Send('get', 'xml')->getArrayData();
        dump($TaobaokeData);
    }

    function Get_Cats($parent_cid, $cids = null) {
        $Taoapi_Config  = Taoapi_Config :: Init();
        $Taoapi_Config->setCharset('UTF-8');
        $Taoapi_Config->setCache(0);
        $Taoapi_Config->setCloseError();
        $Taoapi         = new Taoapi;
        $Taoapi->method = 'taobao.itemcats.get';
        $Taoapi->fields = "cid,parent_cid,name,is_parent";
        if ($parent_cid !== "") {
            $Taoapi->parent_cid = $parent_cid;
        }
        if ($cids != null) {
            $Taoapi->cids = $cids;
        }
        $TaobaokeData = $Taoapi->Send('get', 'xml')->getArrayData();
        $m            = M("taobao_itemcats");
        foreach ($TaobaokeData['item_cats']["item_cat"] as $key => $value) {
            $data = array(
                "cid"        => $value['cid'],
                "is_parent"  => (($value['is_parent'] == "false") ? 0 : 1),
                "name"       => $value['name'],
                "parent_cid" => $value['parent_cid'],
            );
            $m->add($data);
            //Taobao::Get_Cats($value['cid']);
        }
    }

    function Get_ShopCats() {
        $Taoapi_Config  = Taoapi_Config :: Init();
        $Taoapi_Config->setCharset('UTF-8');
        $Taoapi_Config->setCache(0);
        $Taoapi_Config->setCloseError();
        $Taoapi         = new Taoapi;
        $Taoapi->method = 'taobao.shopcats.list.get';
        $Taoapi->fields = "cid,parent_cid,name,is_parent";
        /* if ($parent_cid !== "") {
          $Taoapi->parent_cid = $parent_cid;
          }
          if ($cids != null) {
          $Taoapi->cids = $cids;
          } */
        $TaobaokeData   = $Taoapi->Send('get', 'xml')->getArrayData();
        $m              = M("taobao_shopcats");
        foreach ($TaobaokeData['shop_cats']["shop_cat"] as $key => $value) {
            $data = array(
                "cid"        => $value['cid'],
                "is_parent"  => (($value['is_parent'] == "false") ? 0 : 1),
                "name"       => $value['name'],
                "parent_cid" => $value['parent_cid'],
            );
            $m->add($data);
        }
    }

    function GetAllCategory() {
        $sql   = "SELECT * FROM " . DB::table("app_taobao_tags") . " ORDER BY `category` ASC,`tagid` ASC";
        $query = DB::query($sql);
        $list  = array();
        while ($Result = DB::fetch($query)) {
            $list[$Result['category']][] = $Result;
        }
        return $list;
    }

    function GetItem($num_iids) {
        $Taoapi_Config                                                                       = Taoapi_Config :: Init();
        $Taoapi_Config->setCharset('UTF8');
        $Taoapi_Config->setCache(0);
        $Taoapi_Config->setCloseError();
        $usernick                                                                            = C('usernick');
        $Taoapi                                                                              = new Taoapi;
        $Taoapi->method                                                                      = 'taobao.taobaoke.items.detail.get';
        $Taoapi->fields                                                                      = 'title,nick,pic_url,price,cid,num,post_fee,express_fee,ems_fee,list_time,delist_time,location,click_url,shop_click_url,seller_credit_score';
        $Taoapi->nick                                                                        = $usernick;
        $Taoapi->num_iids                                                                    = $num_iids;
        $TaobaokeData                                                                        = $Taoapi->Send('get', 'xml')->getArrayData();
        $Taoapi->method                                                                      = 'taobao.item.get';
        $Taoapi->fields                                                                      = 'props_name';
        $Taoapi->nick                                                                        = $TaobaokeData['taobaoke_item_details']['taobaoke_item_detail']['item']['nick'];
        $Taoapi->num_iid                                                                     = $num_iids;
        $TaobaokeDatas                                                                       = $Taoapi->Send('get', 'xml')->getArrayData();
        $TaobaokeData['taobaoke_item_details']['taobaoke_item_detail']['item']['props_name'] = $TaobaokeDatas['item']['props_name'];
        preg_match_all('|(\w+):(\w+):([^\/]+):([^\/]+);|U', $TaobaokeData['taobaoke_item_details']['taobaoke_item_detail']['item']['props_name'], $props_name);
        $props                                                                               = array();
        foreach ($props_name[3] as $key => $value) {
            if ($props[$value] == '') {
                $props[$value] = $value . ':' . $props_name[4][$key];
            } else {
                $props[$value].=',' . $props_name[4][$key];
            }
        }

        $TaobaokeData['taobaoke_item_details']['taobaoke_item_detail']['item']['props_name'] = $props;
        // 商品获取
        $info                                                                                = array();
        $taobaoke_item_detail        = $TaobaokeData['taobaoke_item_details']['taobaoke_item_detail'];
        $info['item']                = $taobaoke_item_detail['item'];
        $info['click_url']           = $taobaoke_item_detail['click_url'];
        $info['shop_click_url']      = $taobaoke_item_detail['shop_click_url'];
        $info['seller_credit_score'] = $taobaoke_item_detail['seller_credit_score'];
        $Taoapi                      = new Taoapi;
        $Taoapi->method              = 'taobao.user.get';
        $Taoapi->fields              = 'user_id,nick,sex,buyer_credit,seller_credit,location.city,location.state,location.country,created,last_visit';
        $Taoapi->nick                = $taobaoke_item_detail['item']['nick'];
        $TaobaokeData                = $Taoapi->Send('get', 'xml')->getArrayData();
        if ($Taoapi->getErrorInfo()) {
            show404();
        }
        $info['num_iid'] = $num_iids;
        $info['shop']    = $TaobaokeData['user'];
        return $info;
    }

    function GetItemInfo($id) {
        global $config;
        $filetime = 60;
        $filelist = DISCUZ_ROOT . APP_DATA . "Cache/item{$id}.cache.php";
        if ((filemtime($filelist) < time() - $filetime)) {
            $data = GetItem_Cache($id);
            if (is_array($data)) {
                $content = "<?php !defined('IN_DISCUZ') && exit('Access Denied'); " . '$return=' . var_export($data, TRUE) . "; ?>";
            } else {

                $content = "<?php !defined('IN_DISCUZ') && exit('Access Denied'); " . '$return="' . $data . "\"; ?>";
            }
            file_put_contents($filelist, $content);
        } else {
            include_once($filelist);
            return $return;
        }
        return $data;
    }

    function is_gb2312($str) {
        for ($i = 0; $i < strlen($str); $i++) {
            $v = ord($str[$i]);
            if ($v > 127) {
                if (($v >= 228) && ($v <= 233)) {
                    if (($i + 2) >= (strlen($str) - 1))
                        return true;  // not enough characters
                    $v1 = ord($str[$i + 1]);
                    $v2 = ord($str[$i + 2]);
                    if (($v1 >= 128) && ($v1 <= 191) && ($v2 >= 128) && ($v2 <= 191)) // utf编码
                        return false;
                    else
                        return true;
                }
            }
        }
        return true;
    }

    function GetShop_Else() {
        $Taoapi_Config  = Taoapi_Config :: Init();
        $Taoapi_Config->setCharset('UTF8');
        $Taoapi_Config->setCache(0);
        $Taoapi_Config->setCloseError();
        $usernick       = C('usernick');
        $Taoapi         = new Taoapi;
        $Taoapi->method = 'taobao.taobaoke.items.get';
        $Taoapi->fields = 'num_iid,iid,title,nick,pic_url,price,click_url,commission,commission_rate,commission_num,commission_volume,seller_credit_score,item_location,shop_click_url';
        $Taoapi->nick   = $usernick;
        if ($keyword != "") {
            $Taoapi->keyword = $keyword;
        }
        if ($cid != "") {
            $Taoapi->cid          = $cid;
        }
        $Taoapi->start_credit = '3diamond';
        $Taoapi->end_credit   = '5goldencrown';
        $Taoapi->sort         = 'commissionNum_desc';
        $Taoapi->page_no      = $page;
        $Taoapi->page_size    = $page_size;
        $TaobaokeData         = $Taoapi->Send('get', 'xml')->getArrayData();
    }

    function GetItem_Index($cid = "", $keyword = "", $page = 1, $page_size = 40) {
        $filetime = 60;
        $file     = md5($cid . "_" . $keyword . "_" . $page);
        $filelist = DISCUZ_ROOT . APP_DATA . "Cache/{$file}.cache.php";
        if ((filemtime($filelist) < time() - $filetime)) {
            $Taoapi_Config  = Taoapi_Config :: Init();
            $Taoapi_Config->setCharset('UTF8');
            $Taoapi_Config->setCache(0);
            $Taoapi_Config->setCloseError();
            $usernick       = C('usernick');
            $Taoapi         = new Taoapi;
            $Taoapi->method = 'taobao.taobaoke.items.get';
            $Taoapi->fields = 'num_iid,iid,title,nick,pic_url,price,click_url,commission,commission_rate,commission_num,commission_volume,seller_credit_score,item_location,shop_click_url';
            $Taoapi->nick   = $usernick;
            if ($keyword != "") {
                $Taoapi->keyword = $keyword;
            }
            if ($cid != "") {
                $Taoapi->cid          = $cid;
            }
            $Taoapi->start_credit = '3diamond';
            $Taoapi->end_credit   = '5goldencrown';
            $Taoapi->sort         = 'commissionNum_desc';
            $Taoapi->page_no      = $page;
            $Taoapi->page_size    = $page_size;
            $TaobaokeData         = $Taoapi->Send('get', 'xml')->getArrayData();
            $data                 = $TaobaokeData;
            if (is_array($data)) {
                $content = "<?php !defined('IN_DISCUZ') && exit('Access Denied'); " . '$return=' . var_export($data, TRUE) . "; ?>";
            } else {

                $content = "<?php !defined('IN_DISCUZ') && exit('Access Denied'); " . '$return="' . $data . "\"; ?>";
            }
            file_put_contents($filelist, $content);
        } else {
            include_once($filelist);
            return $return;
        }

        return $data;
    }

    function GetItem_Cache($num_iids, $cache = 0, $write = 0) {
        if ($cache == 0) {
            $Taoapi_Config                                                                       = Taoapi_Config :: Init();
            $Taoapi_Config->setCharset('UTF-8');
            $Taoapi_Config->setCache(0);
            $Taoapi_Config->setCloseError();
            $usernick                                                                            = "vip7086";
            $Taoapi                                                                              = new Taoapi;
            $Taoapi->method                                                                      = 'taobao.taobaoke.items.detail.get';
            $Taoapi->fields                                                                      = 'title,nick,pic_url,price,cid,num,post_fee,express_fee,ems_fee,list_time,delist_time,location,click_url,shop_click_url,seller_credit_score';
            $Taoapi->nick                                                                        = $usernick;
            $Taoapi->num_iids                                                                    = $num_iids;
            $TaobaokeData                                                                        = $Taoapi->Send('get', 'xml')->getArrayData();
            $Taoapi                                                                              = new Taoapi;
            $Taoapi->method                                                                      = 'taobao.taobaoke.items.convert';
            $Taoapi->fields                                                                      = 'commission,commission_rate,commission_num,commission_volume';
            $Taoapi->nick                                                                        = $usernick;
            $Taoapi->num_iids                                                                    = $num_iids;
            $commission                                                                          = $Taoapi->Send('get', 'xml')->getArrayData();
            $Taoapi                                                                              = new Taoapi;
            $Taoapi->method                                                                      = 'taobao.item.get';
            $Taoapi->fields                                                                      = 'props_name';
            $Taoapi->nick                                                                        = $TaobaokeData['taobaoke_item_details']['taobaoke_item_detail']['item']['nick'];
            $Taoapi->num_iid                                                                     = $num_iids;
            $TaobaokeDatas                                                                       = $Taoapi->Send('get', 'xml')->getArrayData();
            $TaobaokeData['taobaoke_item_details']['taobaoke_item_detail']['item']['props_name'] = $TaobaokeDatas['item']['props_name'];
            preg_match_all('|(\w+):(\w+):([^\/]+):([^\/]+);|U', $TaobaokeData['taobaoke_item_details']['taobaoke_item_detail']['item']['props_name'], $props_name);
            $props                                                                               = array();
            foreach ($props_name[3] as $key => $value) {
                if ($props[$value] == '') {
                    $props[$value] = $value . ':' . $props_name[4][$key];
                } else {
                    $props[$value] .= ',' . $props_name[4][$key];
                }
            }
            $TaobaokeData['taobaoke_item_details']['taobaoke_item_detail']['item']['props_name'] = $props;
            // 商品获取
            $taobaoke_item_detail                                                                = $TaobaokeData['taobaoke_item_details']['taobaoke_item_detail'];
            $item                                                                                = $taobaoke_item_detail['item'];
            $item['commission']                                                                  = $commission['taobaoke_items']['taobaoke_item'];
            $item['tourl']                                                                       = 'http://item.taobao.com/item.htm?id=' . $num_iids;
            if (!is_array($taobaoke_item_detail['click_url'])) {
                $item['click_url'] = $taobaoke_item_detail['click_url'];
            } else {
                $item['click_url'] = '';
            }
            if ($Taoapi->getErrorInfo()) {
                return false;
            }
            if ($write == 1) {
                $shop = GetShop($item['nick'], 1);
            } else {
                $shop = GetShop($item['nick']);
            }
            if ($shop == false) {
                return false;
            }
            $data = array(
                'iid'       => $num_iids,
                'sid'       => $shop['sid'],
                'cid'       => $item['cid'],
                'ititle'    => $item['title'],
                'iurl'      => $item['click_url'],
                'ipic'      => $item['pic_url'],
                'icontent'  => '',
                'idateline' => TIMESTAMP
            );
            if ($write == 1) {
                $a                = DB :: insert('app_taobao_share_item', $data, 1);
            }
            $data['icontent'] = $item;
            $item             = $data;
            $item['shop']     = $shop;
        } else {
            //缓存
            $sql  = "SELECT * FROM " . DB :: table('app_taobao_share_item') . " WHERE iid='" . $num_iids . "';";
            $item = DB :: fetch_first($sql);
            if (!$item) {
                $item = GetItem_Cache($num_iids, 0, 1);
            } else {
                //读取缓存文件
                $file     = Get_Cache_File($num_iids);
                $filetime = 2592000;
                if ((filemtime($file) + $filetime < time()) or !file_exists($file)) {
                    //没有文件 或�? 过期
                    $item = GetItem_Cache($num_iids, 0);
                    unset($item['shop']);
                    if (is_array($item)) {
                        $content = "<?php !defined('IN_DISCUZ') && exit('Access Denied'); " . '$item=' . var_export($item, TRUE) . "; ?>";
                    } else {
                        $content = "<?php !defined('IN_DISCUZ') && exit('Access Denied'); " . '$item="' . $item . "\"; ?>";
                    }
                    file_put_contents($file, $content);
                } else {
                    include_once ($file);
                    //有文�?
                }
                $item['shop'] = GetShop($item['icontent']['nick'], 1);
            }
            if ($item['shop'] == false) {
                return false;
            }
        }
        if ($item['iurl'] == '') {
            $item['iurl'] = 'http://item.taobao.com/item.htm?id=' . $num_iids;
        }
        $item['url']  = array(
            'item' => 'http://item.taobao.com/item.htm?id=' . $num_iids,
            'shop' => 'http://shop' . $item['shop']['sid'] . '.taobao.com/'
        );
        return $item;
    }

    function createFolder($path) {
        if (!file_exists($path)) {
            Taobao::createFolder(dirname($path));
            mkdir($path, 0777);
        }
    }

    function Get_Cache_File($iid, $type = "item") {
        $dir = SO_CACHE . "./ItemCache/{$type}/";
        $iid = abs($iid);
        switch ($type) {
            case "item":
                $iid      = str_pad($iid, 15, "0", STR_PAD_LEFT);
                $dir1     = substr($iid, 0, 5);
                $dir2     = substr($iid, 5, 2);
                $dir3     = substr($iid, 7, 2);
                $dir4     = substr($iid, 9, 2);
                $dir5     = substr($iid, 11, 2);
                $dir_full = $dir . $dir1 . '/' . $dir2 . '/' . $dir3 . '/' . $dir4 . '/' . $dir5;
                Taobao::createFolder($dir_full);
                $file     = $dir_full . '/' . substr($iid, -2) . ".php";
                break;
            case "huabao":
                $iid      = sprintf("%09d", $iid);
                $dir1     = substr($iid, 0, 2);
                $dir2     = substr($iid, 2, 2);
                $dir3     = substr($iid, 4, 2);
                $dir4     = substr($iid, 6, 2);
                $dir_full = $dir . $dir1 . '/' . $dir2 . '/' . $dir3 . "/" . $dir4;
                Taobao::createFolder($dir_full);
                $file     = $dir_full . '/' . substr($iid, -2) . ".php";
                break;
            case "shop":
                $iid      = sprintf("%09d", $iid);
                $dir1     = substr($iid, 0, 2);
                $dir2     = substr($iid, 2, 2);
                $dir3     = substr($iid, 4, 2);
                $dir4     = substr($iid, 6, 2);
                $dir_full = $dir . $dir1 . '/' . $dir2 . '/' . $dir3 . "/" . $dir4;
                Taobao::createFolder($dir_full);
                $file     = $dir_full . '/' . substr($iid, -2) . ".php";
                break;
            default:
                break;
        }
        return $file;
    }

    function GetShop($nick, $cache = 0, $write = 0) {
        if ($cache == 0) {
            $Taoapi_Config                = Taoapi_Config :: Init();
            $Taoapi_Config->setCharset('UTF-8');
            $Taoapi_Config->setCache(0);
            $Taoapi_Config->setCloseError();
            $usernick                     = "vip7086";
            $Taoapi                       = new Taoapi;
            $Taoapi->method               = 'taobao.shop.get';
            $Taoapi->fields               = 'sid,cid,title,bulletin,pic_path,created,modified,shop_score';
            $Taoapi->nick                 = $nick;
            $TaobaokeData                 = $Taoapi->Send('get', 'xml')->getArrayData();
            $Taoapi                       = new Taoapi;
            $Taoapi->method               = 'taobao.taobaoke.shops.convert';
            $Taoapi->fields               = 'user_id,shop_title,click_url,commission_rate';
            $Taoapi->sids                 = $TaobaokeData['shop']['sid'];
            $Taoapi->nick                 = $usernick;
            $Urls                         = $Taoapi->Send('get', 'xml')->getArrayData();
            $TaobaokeData['shop']['surl'] = 'http://shop' . $TaobaokeData['shop']['sid'] . '.taobao.com/';
            if ($Urls['taobaoke_shops']['taobaoke_shop']['click_url'] != "") {
                $TaobaokeData['shop']['tourl'] = $Urls['taobaoke_shops']['taobaoke_shop']['click_url'];
            } else {
                $TaobaokeData['shop']['tourl'] = '';
            }
            if ($Taoapi->getErrorInfo()) {
                return false;
            }
            $shop           = $TaobaokeData['shop'];
            $Taoapi         = new Taoapi;
            $Taoapi->method = 'taobao.user.get';
            $Taoapi->fields = 'user_id';
            $Taoapi->nick   = $nick;
            $TaobaokeData   = $Taoapi->Send('get', 'xml')->getArrayData();
            if ($Taoapi->getErrorInfo()) {
                return false;
            }
            $shop['suid'] = $TaobaokeData['user']['user_id'];
            $data         = array(
                'sid'       => $shop['sid'],
                'suid'      => $shop['suid'],
                'stitle'    => $shop['title'],
                'snick'     => $nick,
                'surl'      => $shop['tourl'],
                'scontent'  => '',
                'sdateline' => TIMESTAMP
            );
            if ($write == 1) {
                $a                = DB :: insert('app_taobao_share_shop', $data, 1);
            }
            $data['scontent'] = $shop;
            $shop             = $data;
        } else {
            $sql  = "SELECT * FROM " . DB :: table('app_taobao_share_shop') . " WHERE snick='" . $nick . "';";
            $shop = DB :: fetch_first($sql);
            if (!$shop) {
                $shop = GetShop($nick, 0, 1);
            } else {
                $file     = Get_Cache_File($shop['sid'], 'shop');
                $filetime = 2592000;
                //读取缓存文件
                if ((filemtime($file) + $filetime < time()) or !file_exists($file)) {
                    //没有文件
                    $shop = GetShop($nick, 0);
                    if (is_array($shop)) {
                        $content = "<?php !defined('IN_DISCUZ') && exit('Access Denied'); " . '$shop=' . var_export($shop, TRUE) . "; ?>";
                    } else {

                        $content = "<?php !defined('IN_DISCUZ') && exit('Access Denied'); " . '$shop="' . $shop . "\"; ?>";
                    }
                    file_put_contents($file, $content);
                } else {
                    include_once ($file);
                    //有文�?
                }
            }
        }
        if ($shop['surl'] == '') {
            $shop['surl'] = 'http://shop' . $shop['sid'] . '.taobao.com/';
        }
        return $shop;
    }

    public function taoke_item_get($iids) {
        $Set = array(
            'method'   => 'taobao.taobaoke.items.detail.get',
            'fields'   => 'click_url,shop_click_url,seller_credit_score,num_iid,title,nick,pic_url,detail_url,price',
            'nick'     => 'vip7086',
            'num_iids' => $iids
        );

        $Data = Taobao::Auto_Get($Set);

        if ($Data['total_results'] == 0) {
            $Data['taobaoke_item_details']['taobaoke_item_detail'] = array();
        }
        if ($Data['total_results'] == 1) {
            $Data['taobaoke_item_details']['taobaoke_item_detail'] = array($Data['taobaoke_item_details']['taobaoke_item_detail']);
        }
        return $Data['taobaoke_item_details']['taobaoke_item_detail'];
    }

    public function item_get($iid) {
        $Set = array(
            'method'  => 'taobao.item.get',
            'fields'  => 'num_iid,title,nick,pic_url,detail_url,price,location',
            'nick'    => 'vip7086',
            'num_iid' => $iid
        );

        $Data = Taobao::Auto_Get($Set);
        return $Data['item'];
    }

}

class Huabao extends Taobao {

    function Get_Channels() {
        $Set = array(
            'method' => 'taobao.poster.channels.get',
        );
        $Data    = Taobao::Auto_Get($Set);
        $m       = M("huabao_channels");
        foreach ($Data['channels']["huabao_channel"] as $key => $value) {
            $data = array(
                "id"           => $value['id'],
                "channel_name" => $value['channel_name'],
                "channel_url"  => $value['channel_url'],
                "name_en"      => $value['name_en'],
                "description"  => $value['description'],
                "status"       => 0,
            );
            $m->add($data);
            //Taobao::Get_Cats($value['cid']);
        }
    }

}

?>